<?php

namespace app\api\controller;
//use app\common\library\Sms as Smslib;
use think\facade\Request;
use app\common\controller\Api;
use think\facade\Db;
class Monitor extends Api
{   
    /**
     * 埋点监控日志接口
     * 不需要鉴权方法
     * index、save不需要鉴权
     * ['index','save']
     * 所有方法都不需要鉴权
     * [*]
     */
    protected $noNeedLogin = ['*'];
    // protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function monitor(){
    	$params = $this->request->post();
    	if (!isset($params['url_id']) || $params['url_id'] == null){
            $this->error('缺少参数url_id');
        }
        if (!isset($params['province'])){
            $this->error('缺少参数province');
        }
        if (!isset($params['province_name'])){
            $this->error('缺少参数province_name');
        }
        if (!isset($params['assets_id']) || $params['assets_id'] == null){
            $this->error('缺少参数assets_id');
        }
        if (!isset($params['channel_id'])){
            $this->error('缺少参数channel_id');
        }
        if (!isset($params['event_id']) || $params['event_id'] == null){
            $this->error('缺少参数event_id');
        }
        if (!isset($params['bus_code'])){
            $this->error('缺少参数bus_code');
        }
        if (!isset($params['mobile'])){
            $this->error('缺少参数mobile');
        }
        if (!isset($params['status'])){
            $this->error('缺少参数status');
        }
		$params['add_time'] = time();
		$params['day_time'] = strtotime(date('Y-m-d',time()));
		$result = Db::name('monitor')->insert($params);
    	if ($result) {
    	    $this->success(__('添加成功'));
    	} else {
    	    $this->error(__('添加失败'));
    	}
    }
	//所有的事件
	public function event(){
		//查出所有的事件
		$list = Db::name('event')->select();
		// halt($list);
		$this->success('事件列表',$list);
	}
}
